package com.zhouyu.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;

@Service
public class OrderService {



	@Autowired
	JdbcTemplate jdbcTemplate;

	@Autowired
	OrderService orderService;

	@Transactional
	public void one() {
//		jdbcTemplate.execute("insert into test values(1,'1')");
//		try {
//			orderService.two();
//		}catch (Exception e){
//
//		}
		System.out.println(TransactionSynchronizationManager.getCurrentTransactionName());

		//

		try {
			orderService.two();
		}catch (Exception e){

		}
	}

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public void two()  {
//		jdbcTemplate.execute("insert into test values(2,'2')");
//		throw new NullPointerException() ;

		System.out.println(TransactionSynchronizationManager.getCurrentTransactionName());
	}
}
